Skip to content

fix(cookbook-app-react-state): migrate routing to Fusion route DSL - #5229

Merged
odinr merged 1 commit into
mainfrom
fix/app-react-state-route-dsl
Aug 8, 2026
Merged

fix(cookbook-app-react-state): migrate routing to Fusion route DSL#5229
odinr merged 1 commit into
mainfrom
fix/app-react-state-route-dsl

Conversation

@odinr

@odinr odinr commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Why is this change needed?
app-react-state's router was the only cookbook still using a hand-written RouteObject[] tree, inconsistent with the file-based route DSL (layout/index/route from @equinor/fusion-framework-react-router/routes) already used by app-react-router, app-react-people, and app-react-charts. Its sidebar active-link check also had a latent bug.

What is the current behavior?

  • src/Router.tsx built a RouteObject[] array inline, importing page components from a src/pages/ barrel.
  • src/pages/Root.tsx's sidebar marked a link active only on an exact pathname match (pathname === '/basics'), even though the route is declared with a /* wildcard (basics/*), so a link would not stay highlighted on a matching sub-path.

What is the new behavior?

  • Routes are now defined with the DSL in src/routes/routes.ts (layout('./layout.tsx', [index(...), route(...), ...])), matching the app-react-router cookbook's src/routes/ layout.
  • Pages moved into src/routes/ (layout.tsx, index.tsx, basics/index.tsx, profile/index.tsx, todos/index.tsx); the now-unused src/pages/index.ts barrel was removed.
  • The sidebar active-link check now uses prefix matching (pathname === path || pathname.startsWith(path + '/')), consistent with app-react-router's Navigation.tsx.

What is the intended behavior or invariant?
Route definitions and page components stay under src/routes/; sidebar links are active for their route path and any of its sub-paths.

Does this PR introduce a breaking change?
No. This is a cookbook (non-published-API) internal restructuring; the rendered app behavior is unchanged apart from the active-link fix.

Impact assessment:

  • Breaking changes: No
  • Version bump: Patch (changeset added against @equinor/fusion-framework-cookbook-app-react-state)
  • Consumer impact: None (cookbook demo app only)
  • Downstream impact: None

Review guidance:
Focus on src/routes/routes.ts (route tree) and the isActive helper in src/routes/layout.tsx. Verified with tsc -b --force, Biome, and fusion-lint (all clean).

Related issues
None.

Checklist

  • Confirm completion of the self-review checklist
  • Confirm TSDoc captures intent for functions, hooks, components, classes, and named arrow functions
  • Confirm iterator blocks, decision gates, RxJS chains, and complex decisions explain why they exist
  • Confirm React logic and derived values are resolved before markup when applicable
  • Confirm README/docs are updated for user-facing changes (n/a - internal cookbook restructuring)
  • Confirm changes to target branch validation
    • Included files validated
    • No new linting warnings
    • Not a duplicate PR
  • Confirm adherence to code of conduct

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2c98883

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@equinor/fusion-framework-cookbook-app-react-state Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added 🐞 bug Something isn't working 👨🏻‍🍳 cookbooks labels Aug 7, 2026
@odinr
odinr marked this pull request as ready for review August 7, 2026 10:50
@odinr
odinr requested a review from a team as a code owner August 7, 2026 10:50
@odinr odinr self-assigned this Aug 7, 2026
@odinr
odinr requested a lite review from Copilot August 7, 2026 10:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the app-react-state cookbook from a hand-authored RouteObject[] tree to the Fusion route DSL (layout/index/route) to align with the other routing-based cookbooks, and fixes the sidebar active-link logic so links remain active for matching sub-routes.

Changes:

  • Replace inline RouteObject[] routing in src/Router.tsx with a route DSL manifest (src/routes/routes.ts).
  • Move/align pages under src/routes/ and update imports accordingly; remove the now-unused src/pages/ barrel.
  • Fix sidebar “active link” detection to match both exact paths and /* sub-paths.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cookbooks/app-react-state/src/Router.tsx Switch router setup to consume the route DSL manifest instead of inline RouteObject[].
cookbooks/app-react-state/src/routes/routes.ts Introduce the route DSL tree (layout + index/route) as the canonical route definition.
cookbooks/app-react-state/src/routes/layout.tsx Fix sidebar active-link logic to stay active on matching sub-paths.
cookbooks/app-react-state/src/routes/index.tsx Add the cookbook “home” route module under the new src/routes/ structure.
cookbooks/app-react-state/src/routes/basics/index.tsx Add the “basics” route module under the new src/routes/ structure.
cookbooks/app-react-state/src/routes/profile/index.tsx Update import path after moving route modules under src/routes/.
cookbooks/app-react-state/src/routes/todos/index.tsx Update import path after moving route modules under src/routes/.
cookbooks/app-react-state/src/pages/index.ts Remove the unused pages barrel export after the routing migration.
.changeset/cookbook-app-react-state_route-dsl.md Add a patch changeset for the cookbook routing migration + active-link fix.

Migrate app-react-state's Router.tsx from a hand-written RouteObject[]
tree to the layout/index/route DSL from
@equinor/fusion-framework-react-router/routes, matching the pattern
used by app-react-router/app-react-people/app-react-charts. Pages now
live under src/routes/ (routes.ts + layout.tsx + per-route folders).

Also fixes the sidebar active-link check in the layout, which
previously did an exact pathname match even though routes are declared
with a /* wildcard (basics/*, profile/*, todos/*) - now uses prefix
matching so a link stays active on any sub-path.
@odinr
odinr force-pushed the fix/app-react-state-route-dsl branch from 5935d8c to 2c98883 Compare August 8, 2026 16:26
@odinr
odinr merged commit fd873c7 into main Aug 8, 2026
8 checks passed
@odinr
odinr deleted the fix/app-react-state-route-dsl branch August 8, 2026 16:26
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 67.13% 3931 / 5855
🔵 Statements 66.87% 4697 / 7024
🔵 Functions 53.54% 1361 / 2542
🔵 Branches 55.77% 2063 / 3699
File CoverageNo changed files found.
Generated in workflow #15193 for commit 2c98883 by the Vitest Coverage Report Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants